package jjn.carl.greedy;

import java.util.Scanner;

/**
 * @author Jjn
 * @since 2023/7/29 19:58
 */
public class LeetCode122 {
    public int maxProfit(int[] prices) {
        int max = 0;
        for (int i = 1; i < prices.length; i++) {
            if (prices[i] >= prices[i - 1]) {
                max += prices[i] - prices[i - 1];
            }
        }
        return max;
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count = scanner.nextInt();
        int[] prices = new int[count];
        for (int i = 0; i < count; i++) {
            prices[i] = scanner.nextInt();
        }
        int maxProfit = new LeetCode122().maxProfit(prices);
        System.out.println(maxProfit);
    }
}
